package com.atguigu.edu.pubshier.controller;

import com.alibaba.fastjson.JSON;
import com.atguigu.edu.pubshier.beans.DataInfo;
import com.atguigu.edu.pubshier.beans.ResponseVO;
import com.atguigu.edu.pubshier.service.FavorableRateService;
import com.atguigu.edu.pubshier.utils.DateFormatUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * @author: 洛尘
 * @since: 2023-10-23 15:59
 * @description:
 **/
@RestController
public class FavorableRateController {
    @Autowired
    FavorableRateService favorableRateService;

    @RequestMapping("/rate")
    public String getRate(@RequestParam(value = "date", defaultValue = "0") Integer date){
        if (date==0){
            date=DateFormatUtil.now();
        }
        List<Map<String, BigDecimal>> favorableRateList = favorableRateService.getFavorableRate(date);
        ResponseVO<List<Map<String, BigDecimal>>> dataInfoResponseVO = new ResponseVO<>();
        dataInfoResponseVO.setStatus(0);
        dataInfoResponseVO.setData(favorableRateList);
        return JSON.toJSONString(dataInfoResponseVO);
    }
}